<?php

namespace app\index\common\logchecker\Parsers;

abstract class BaseParser
{
	/**
	 * The raw contents of the log.
	 *
	 * @var string;
	 */
	protected $log;

	/**
	 * The contents of the log converted to a PHP array.
	 *
	 * @var array
	 */
	public $data;

	/**
	 * The contents of the log converted to JSON.
	 *
	 * @var string
	 */
	protected $json;

	/**
	 * BaseParser constructor. Initializes the
	 * class with the log file.
	 *
	 * @param $log
	 */
	public function __construct($log)
	{
		$this->log = $log;
		$this->parse($log);
	}

	/**
	 * Return the contents of the log in JSON format.
	 *
	 * @return string
	 */
	public function getJson()
	{
		return $this->json;
	}

	/**
	 * Parse the contents of the log file to JSON.
	 * Return true on success and false on failure.
	 *
	 * @param $log
	 *
	 * @return bool
	 */
	abstract public function parse($log);

	/**
	 * Find the version of the software that was used.
	 *
	 * @return string
	 */
	abstract protected function getSoftwareVersion();

	/**
	 * Find the date on which the log was created.
	 *
	 * @return string
	 */
	abstract protected function getLogDate();

	/**
	 * Find the album artist.
	 *
	 * @return string
	 */
	abstract protected function getAlbumArtist();

	/**
	 * Find the album name.
	 *
	 * @return string
	 */
	abstract protected function getAlbumName();

	/**
	 * Find the drive that was used to rip the CD.
	 *
	 * @return string
	 */
	abstract protected function getDriveName();

	/**
	 * Find the checksum of the CD rip.
	 *
	 * @return string
	 */
	abstract protected function getChecksum();

	/**
	 * Find whether the log contains the text 'All tracks accurately ripped'.
	 *
	 * @return bool
	 */
	abstract protected function getAllTracksAccuratelyRipped();

	/**
	 * Find out whether the log contains the text 'No errors occurred'.
	 *
	 * @return bool
	 */
	abstract protected function getNoErrorsOccurred();

	/**
	 * Find the read mode that was used.
	 *
	 * @return string
	 */
	abstract protected function getReadMode();

	/**
	 * Find whether accurate stream was utilized.
	 *
	 * @return bool
	 */
	abstract protected function getAccurateStream();

	/**
	 * Find whether defeat audio cache is enabled.
	 *
	 * @return bool
	 */
	abstract protected function getDefeatAudioCache();

	/**
	 * Find whether C2 Pointers are used.
	 *
	 * @return bool
	 */
	abstract protected function getC2Pointers();

	/**
	 * Find the read offset correction.
	 *
	 * @return int|string
	 */
	abstract protected function getReadOffsetCorrection();

	/**
	 * Find whether overread into lead-in and lead-out
	 * is enabled.
	 *
	 * @return bool
	 */
	abstract protected function getOverreadIntoLeadinLeadOut();

	/**
	 * Find whether "Fill up missing offset samples with silence"
	 * is used.
	 *
	 * @return bool
	 */
	abstract protected function getFillUpOffsetSamples();

	/**
	 * Find out whether leading and trailing silent blocks
	 * are deleted.
	 *
	 * @return bool
	 */
	abstract protected function getDeleteSilentBlocks();

	/**
	 * Find out whether null samples are used in CRC calculations.
	 *
	 * @return bool
	 */
	abstract protected function getNullSamplesUsed();

	/**
	 * Get the interface that was used.
	 *
	 * @return string
	 */
	abstract protected function getUsedInterface();

	/**
	 * Get the gap handling mode that was used.
	 *
	 * @return string
	 */
	abstract protected function getGapHandling();

	/**
	 * Get the output format that was used.
	 *
	 * @return string
	 */
	abstract protected function getUsedOutputFormat();

	/**
	 * Find the bitrate in kilobits.
	 *
	 * @return int|string
	 */
	abstract protected function getSelectedBitrate();

	/**
	 * Find the output quality that was used.
	 *
	 * @return string
	 */
	abstract protected function getOutputQuality();

	/**
	 * Find whether ID3 tags were added or not.
	 *
	 * @return bool
	 */
	abstract protected function getID3TagsAdded();

	/**
	 * Get the executable that was used to compress the
	 * .wav files.
	 *
	 * @return string
	 */
	abstract protected function getCompressorExecutable();

	/**
	 * Find track data by track number.
	 *
	 *
	 * @return array
	 */
	abstract protected function getTrackData();

	/**
	 * Get the filename of a given track.
	 *
	 * @param int $pos
	 *
	 * @return string
	 */
	abstract protected function getTrackFileName($pos);

	/**
	 * Get the pregap length for a given track.
	 *
	 * @param int $pos
	 *
	 * @return string
	 */
	abstract protected function getTrackPregapLength($pos);

	/**
	 * Gets the peak level for a given track.
	 *
	 * @param int $pos
	 *
	 * @return float
	 */
	abstract protected function getTrackPeakLevel($pos);

	/**
	 * Gets the extraction speed for a given track.
	 *
	 * @param int $pos
	 *
	 * @return float|string
	 */
	abstract protected function getTrackExtractionSpeed($pos);

	/**
	 * Gets the track quality for a given track.
	 *
	 * @param int $pos
	 *
	 * @return float
	 */
	abstract protected function getTrackQuality($pos);

	/**
	 * Gets the test CRC for a given track.
	 *
	 * @param int $pos
	 *
	 * @return string
	 */
	abstract protected function getTrackTestCrc($pos);

	/**
	 * Gets the copy CRC for a given track.
	 *
	 * @param int $pos
	 *
	 * @return string
	 */
	abstract protected function getTrackCopyCrc($pos);

	/**
	 * Gets the AccurateRip confidence level for a given track.
	 *
	 * @param int $pos
	 *
	 * @return int
	 */
	abstract protected function getTrackAccurateRipConfidence($pos);

	/**
	 * Get the copy result for a given track.
	 *
	 * @param int $pos
	 *
	 * @return string
	 */
	abstract protected function getTrackCopyResult($pos);
}
